<?php

class Helper extends CController
{
        public static function truncate_utf8_string($string, $length, $etc = '...')
        {
            $result = '';
            $string = html_entity_decode(trim(strip_tags($string)), ENT_QUOTES, 'UTF-8');
            $strlen = strlen($string);
            for ($i = 0; (($i < $strlen) && ($length > 0)); $i++)
                {
                if ($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0'))
                        {
                    if ($length < 1.0)
                                {
                        break;
                    }
                    $result .= substr($string, $i, $number);
                    $length -= 1.0;
                    $i += $number - 1;
                }
                        else
                        {
                    $result .= substr($string, $i, 1);
                    $length -= 0.5;
                }
            }
            $result = htmlspecialchars($result, ENT_QUOTES, 'UTF-8');
            if ($i < $strlen)
                {
                        $result .= $etc;
            }
            return $result;
        }
        
        public static function check($temp)
        {
                if($temp==0)
                    return "未参加";
                else
                    return "<font color='green'>已参加</font>";
        }
        
        public static function sex($temp)
        {
                if($temp==0)
                    return "男";
                else
                    return "女";
        }
        
         public static function ctype($temp)
        {
                if($temp==1)
                    return "文章";
                else if($temp==2){
                     return "视频";
                }
                else if($temp==3){
                     return "介绍";
                }
                else if($temp==4){
                     return "课程资料";
                }
                
                 return "";
        }
        
        public static function ctypeList(){
            
              return  array('1'=>'文章',
                            '2'=>'视频',
                            '3'=>'介绍',
                            '4'=>'课程资料',);
        }
        
        
        public static function payFloat($temp)
        {
                if($temp==0)
                    return "<font color='green'>已支付</font>";
                else
                    return "未支付";
        }
        
        
}
